package org.apache.dubbo.common.threadpool;

import org.apache.dubbo.common.threadpool.ThreadPool;
import org.apache.dubbo.rpc.model.ScopeModel;
import org.apache.dubbo.rpc.model.ScopeModelUtil;

public class ThreadPool$Adaptive implements ThreadPool {
    public java.util.concurrent.Executor getExecutor(org.apache.dubbo.common.URL url) {

        String extName = url.getParameter("threadpool", "fixed");
        if (extName == null)
            throw new IllegalStateException("Failed to get extension (org.apache.dubbo.common.threadpool.ThreadPool) name from url (" + url.toString() + ") use keys([threadpool])");

        ScopeModel scopeModel = ScopeModelUtil.getOrDefault(url.getScopeModel(), ThreadPool.class);

        ThreadPool extension = (ThreadPool)
                scopeModel.getExtensionLoader(ThreadPool.class).getExtension(extName);

        return extension.getExecutor(url);
    }
}
